package controller

//各类日统计报表，游戏日报表，盈亏报表
import (
	"admin/model"
	"common/helper"
	"encoding/json"
	"github.com/valyala/fasthttp"
)

type ReportDailyController struct{}

// 日况数据修正
func (that *ReportDailyController) FixDaily(ctx *fasthttp.RequestCtx) {
	from := string(ctx.QueryArgs().Peek("from")) //开始时间
	to := string(ctx.QueryArgs().Peek("to"))     //结束时间
	res := model.FixDailyData(from, to)
	if res {
		helper.RetData(ctx, true, "success")
	} else {
		helper.RetData(ctx, true, "error")
	}

}

// 游戏日况数据修正
func (that *ReportDailyController) FixGmaeDailyData(ctx *fasthttp.RequestCtx) {
	from := string(ctx.QueryArgs().Peek("from")) //开始时间
	to := string(ctx.QueryArgs().Peek("to"))     //结束时间
	res := model.FixGameDaily(from, to)
	if res {
		helper.RetData(ctx, true, "success")
	} else {
		helper.RetData(ctx, true, "error")
	}

}
func (this *ReportDailyController) UserList(ctx *fasthttp.RequestCtx) {
	param := model.ReportDailyParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	if param.Page < 1 {
		param.Page = 1
	}

	if param.PageSize < 10 || param.PageSize > 3000 {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.ReportUserDailyList(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}

	helper.RetData(ctx, true, s)
}

func (this *ReportDailyController) PlatformList(ctx *fasthttp.RequestCtx) {
	param := model.ReportDailyParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	param.IsOperator = ctx.QueryArgs().GetUintOrZero("is_operator")
	param.IsBusiness = ctx.QueryArgs().GetUintOrZero("is_business")

	if param.Page < 1 {
		param.Page = 1
	}

	if param.PageSize < 10 || param.PageSize > 3000 {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.ReportPlatformDailyList(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}

func (this *ReportDailyController) GameList(ctx *fasthttp.RequestCtx) {
	param := model.GameDailyParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}
	param.IsOperator = ctx.QueryArgs().GetUintOrZero("is_operator")
	param.IsBusiness = ctx.QueryArgs().GetUintOrZero("is_business")
	if param.Page < 1 {
		param.Page = 1
	}

	if param.PageSize < 10 || param.PageSize > 3000 {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.ReportGameDailyList(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}

func (this *ReportDailyController) ProxyDailyList(ctx *fasthttp.RequestCtx) {
	param := model.ReportProxyParam{}
	err := json.Unmarshal(ctx.PostBody(), &param)
	if err != nil {

		helper.RetData(ctx, false, "参数错误")
		return
	}

	if param.Page < 1 {
		param.Page = 1
	}

	if param.PageSize < 10 || param.PageSize > 3000 {
		helper.RetData(ctx, false, "参数错误")
		return
	}

	s, err := model.ProxyDailyList(param, ctx)
	if err != nil {
		helper.RetData(ctx, false, err.Error())
		return
	}
	helper.RetData(ctx, true, s)
}
